package typejump.engine;

/**
 * Stores information about what types of collisions are legal with this object
 * (what can collide with me, and what I can collide with)
 * @author g
 *
 */
public class CollisionProps {
	/** No type */
	public static final int T_NONE  = 0;
	/** Geometry, like walls and stuff */
	public static final int T_GEOM 	= 1;
	/** Actors, like NPCs and the Player (this is derived) */
	public static final int T_ACTOR = 2;
	/** Items, which can be picked up by the player */
	public static final int T_ITEM 	= 4;
	/** The Player character */
	public static final int T_PC    = 8;
	/** NPCs */
	public static final int T_NPC   = 16;
	
	/** Which types of objects this can hit */
	private int intTypes = 0;
	/** Which types of objects this object is */
	private int types = 0;
	
	/**
	 * Creates a new collision properties object
	 * Eg: new CollisionProp(CollisionProps.TYPE_ACTOR, CollisionProps.TYPE_GEOM|CollisionProps.TYPE_ITEM)
	 * @param myType - What kind of things I am
	 * @param hitTypes - What kind of things I can hit.
	 */
	public CollisionProps(int myType, int hitTypes) {
		this.types = myType;
		this.intTypes = hitTypes;
		
		// Derived types
		if (hasType(T_NPC) || hasType(T_PC))
			this.types |= T_ACTOR;
	}
	
	/**
	 * Returns true if this is of the given type (eg, 
	 * an object that is T_ITEM and T_GEOM would return true
	 * for T_ITEM)
	 * @param type
	 * @return
	 */
	public boolean hasType(int type) {
		return (type & types) > 0; 
	}
	
	/**
	 * Returns true if this object can hit the other object
	 * (the inverse is not checked)
	 * @param other
	 * @return
	 */
	public boolean canHit(CollisionProps other) {
		return (intTypes & other.types) > 0;
	}
}
